var path = require("path");
var config = require("./config");
var base = require("./base.config.js");
var merge = require("webpack-merge");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var webpack = require("webpack");
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')

Object.keys(base.entry).forEach(function(name) {
    base.entry[name] = ['./webpack/dev-client'].concat(base.entry[name])
})

module.exports = merge(base, {
    resolve: {
        extensions: [".js"]
    },
    module: {
        rules: [{
            test: /\.vue$/,
            loader: "vue-loader",
            options: {
                loaders: {
                    css: "vue-style-loader!css-loader!postcss-loader",
                    less: "vue-style-loader!css-loader!postcss-loader!less-loader"
                }
            }
        }]
    },
    plugins: [
        new webpack.LoaderOptionsPlugin({
            options: {
                postcss: function() {
                    return [
                        require("autoprefixer")({
                            browsers: ['last 3 versions', 'not IE < 10']
                        })
                    ]
                }
            }
        }),
        new HtmlWebpackPlugin({
            template: path.resolve(config.PATH_DOCUMENT, "index.html"),
            filename: path.resolve(config.PATH_BUILD, "document.html"),
            inject: true
        }),
        new webpack.HotModuleReplacementPlugin(),
        new FriendlyErrorsPlugin()
    ]
})